﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using SevenInvaders.common;

namespace SevenInvaders.LEVEL_ANA
{
    class Level_Ana
    {
        AnaPlayer anaPlayer;
        AnaEnemy anaEnemy;
        Texture2D fundodetela;
       
        public static Texture2D anatiro;

        //float addEnemy;

        public Level_Ana(ContentManager Content, GameWindow Window)
        {
            
            
            anaPlayer = new AnaPlayer(Content.Load<Texture2D>("LEVEL_ANA/analevel"), new Vector2(Window.ClientBounds.Width/2, Window.ClientBounds.Height), 1, Window, Content);
            //anaEnemy = new AnaEnemy(Content.Load<Texture2D>("LEVEL_ANA/anaenemy"));
            fundodetela = Content.Load<Texture2D>("LEVEL_ANA/fundo");
            anatiro = Content.Load<Texture2D>("LEVEL_ANA/tiro");

            for (int i = 0; i < 5; i++)
            {
                AnaEnemy.list.Add(new AnaEnemy(Content.Load<Texture2D>("LEVEL_ANA/anaenemy"), new Vector2(120 * i, 120)));
            }
        }

        public void Update(GameTime gameTime, KeyboardState teclado, KeyboardState teclado_anterior)
        {
            
            anaPlayer.Update(gameTime, teclado, teclado_anterior);
            
            for (int i = 0; i < Shoot.list.Count; i++)
            {
                Shoot.list[i].Update(gameTime);

                if (Shoot.list[i].PositionY < -Shoot.list[i].Texture.Height)
                {
                    Shoot.list[i].Visible = false;
                }

                for (int j = 0; j < AnaEnemy.list.Count; j++)
                {
                    if (Shoot.list[i].Collision.Intersects(AnaEnemy.list[j].Collision)
                        && Shoot.list[i].Visible && AnaEnemy.list[j].Visible)
                    {
                        AnaEnemy.list[j].Visible = false;
                        Shoot.list[i].Visible = false;

                    }
                }
            }

            for (int i = 0; i < AnaEnemy.list.Count; i++)
            {
                AnaEnemy.list[i].Update(gameTime);
            }

            for (int i = 0; i < AnaEnemy.list.Count; i++)
            {
                if (!AnaEnemy.list[i].Visible)
                {
                    AnaEnemy.list.RemoveAt(i);
                }
            }

              

        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(fundodetela, Vector2.Zero, Color.White);

            for (int i = 0; i < Shoot.list.Count; i++)
            {
                Shoot.list[i].Draw(gameTime, spriteBatch);
            }
            
            anaPlayer.Draw(gameTime, spriteBatch);

            for (int i = 0; i < AnaEnemy.list.Count; i++)
            {
                AnaEnemy.list[i].Draw(gameTime, spriteBatch);
            }
            
        }
    }
}
